package com.osgi.desktop.bundle;

import com.onetwork.core.actions.OpenMainWindowBundleAction;
import com.onetwork.core.ui.components.BasicWindow;
import com.osgi.desktop.services.TabbedPaneService;
import com.osgi.desktop.services.ToolBarService;
import javax.swing.JButton;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;

public class BasicActivator implements BundleActivator {
    protected ServiceReference toolBarServiceReference;
    protected ServiceReference tabbedPaneServiceReference;
    protected ToolBarService toolBarService;
    protected TabbedPaneService tabbedPaneService;
    
    @Override
    public void start(BundleContext bundleContext) throws Exception {
        toolBarServiceReference = bundleContext.getServiceReference(ToolBarService.class.getName());
        tabbedPaneServiceReference = bundleContext.getServiceReference(TabbedPaneService.class.getName());
        toolBarService = (ToolBarService)bundleContext.getService(toolBarServiceReference);
        tabbedPaneService = (TabbedPaneService)bundleContext.getService(tabbedPaneServiceReference);
        this.myStart(bundleContext);
    }

    @Override
    public void stop(BundleContext bundleContext) throws Exception {
        this.myStop(bundleContext);
        bundleContext.ungetService(toolBarServiceReference);
        bundleContext.ungetService(tabbedPaneServiceReference);
    }
    
    protected void myStart(BundleContext bundleContext) throws Exception {};
    protected void myStop(BundleContext bundleContext) throws Exception {};
    
    protected JButton addActionInToolBar(OpenMainWindowBundleAction action) {
        return toolBarService.addActionInToolBar(action);
    }
    
    protected void removeActionFromToolBar(JButton button) {
        toolBarService.removeActionFromToolBar(button);
    }
    
    protected void removeBasicWindow(BasicWindow basicWindow) {
        tabbedPaneService.removeBasicWindow(basicWindow);
    }
}
